package kr.co.pension.admin.pe.ti.controller;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.pension.admin.pe.ti.service.PETIService;
import kr.co.pension.admin.pe.ti.vo.PETIVo;
import kr.co.pension.usr.pe.re.service.MailService;
import kr.co.pension.usr.pe.re.vo.AddUsrVo;
import kr.co.pension.usr.pe.re.vo.PEREVo;
import kr.co.pension.utils.BaseController;
import kr.co.pension.utils.ConstValue;
import kr.co.pension.utils.PaginationInfo;
import kr.co.pension.utils.SMCommonUtil;
import nl.captcha.Captcha;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

/**
 * 펜션관리
 * @author devhw
 *
 */
@Controller
@RequestMapping("/pmgr/pe/ti/*")
public class PETIController extends BaseController{
	@Autowired
	private PETIService service;

	@Autowired
	private MailService mailService;

	

	Logger log = Logger.getLogger(getClass());
	
	//파일 업로드 폴더 설정
	private final String FILE_PATH= ConstValue.TOP_UPLOAD+ "/peti";

	
	/**
	 *  펜션 조회
	 * @param vo
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping
	public ModelAndView peti100Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();

//		// 페이징 시작
		PaginationInfo paginationInfo = new PaginationInfo();
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));


		int iTotalCnt = service.peti100_1Q(vo);
		vo.setTotalRecordCount(iTotalCnt);
		
		if(iTotalCnt>0){
			
			// 상위 코드목록
			mav.addObject("list", service.peti100_2Q(vo));
			mav.addObject("pageHtml", vo.getToHtml("./peti100Q.do"));
			mav.addObject("paginationInfo", vo);
		}
		
		
		return mav;
		
	}
	
	/**
	 * 펜션정보 삭제
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti101T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti100Q.do");
		mav.addObject("msg","삭제되었습니다.");
		service.peti101T(vo);
		return mav;
	}
	
	/**
	 * 펜션 등록폼
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti200Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		return mav;
	}
	
	
	/**
	 *  펜션 등록 프로세스
	 * @param vo
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping
	public ModelAndView peti200T(HttpServletRequest req, HttpServletResponse res,MultipartHttpServletRequest mRqst) throws Exception {
		isAdminMember(req,res);
		PETIVo vo = new PETIVo();
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti100Q.do");
		
		SMCommonUtil util = new SMCommonUtil();
		util.mapToBean(req.getParameterMap(), vo);

		MultiValueMap mulitFileMap =  mRqst.getMultiFileMap();
		
		String[] files = {"p_logo","footer_logo","event_img","c_back_img"};
		Map fileMap = util.getFileInfo(mulitFileMap, mRqst.getSession().getServletContext().getRealPath(""),FILE_PATH,false, files);
		
		if("Y".equals((String)fileMap.get("error_yn"))){
			mav.addObject("msg",fileMap.get("error_msg"));
			return mav;
		}
		
		if(null!=fileMap.get("p_logo")){
			vo.setP_logo((String) fileMap.get("p_logo"));
		}
		if(null!=fileMap.get("footer_logo")){
			vo.setFooter_logo((String) fileMap.get("footer_logo"));
		}
		if(null!=fileMap.get("event_img")){
			vo.setEvent_img((String) fileMap.get("event_img"));
		}
		if(null!=fileMap.get("c_back_img")){
			vo.setC_back_img((String) fileMap.get("c_back_img"));
		}
		
		
		int cnt  = service.peti100T(vo);
		if(cnt==0){
//			mav = new ModelAndView("redirect:./peti100Q.do?returnCode=0000");\
			mav.addObject("msg","저장되었습니다.");
		}else{
//			mav = new ModelAndView("redirect:./peti100Q.do?returnCode=0001");
			mav.addObject("msg","중복된아이디가 있습니다.");
		}
		
		return mav;
		
	}
	
	
	/**
	 * 상세조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti300Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("map", service.peti300Q(vo));
		List aList = service.peti300_1Q(vo);
		
		List aList1=new ArrayList();
		List aList2=new ArrayList();
		List aList3=new ArrayList();
		List aList4=new ArrayList();
		
		if(aList!=null && 0<aList.size()){
			for( int i=0; i< aList.size();i++){
				Map map = (Map) aList.get(i);
				if("1".equals(map.get("paa_type"))){
					//계좌
					aList1.add(map);
				}else if("2".equals(map.get("paa_type"))){
					//픽업장소
					aList2.add(map);
				}else if("3".equals(map.get("paa_type"))){
					//픽업정보
					aList3.add(map);
				}else if("4".equals(map.get("paa_type"))){
					//도착시간
					aList4.add(map);
				}
			}
		}
		mav.addObject("aList1", aList1);
		mav.addObject("aList2", aList2);
		mav.addObject("aList3", aList3);
		mav.addObject("aList4", aList4);
		return mav;
	}
	
	/**
	 * 펜션 정보 수정 프로세스
	 * @param req
	 * @param res
	 * @param mRqst
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping
	public ModelAndView peti400T(HttpServletRequest req, HttpServletResponse res,MultipartHttpServletRequest mRqst) throws Exception {
		isAdminMember(req,res);
		PETIVo vo = new PETIVo();
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti100Q.do");
		
		SMCommonUtil util = new SMCommonUtil();
		util.mapToBean(req.getParameterMap(), vo);

		MultiValueMap mulitFileMap =  mRqst.getMultiFileMap();
		
		String[] files = {"p_logo","footer_logo","event_img","c_back_img"};
		Map fileMap = util.getFileInfo(mulitFileMap, mRqst.getSession().getServletContext().getRealPath(""),FILE_PATH,false, files);
		
		if("Y".equals((String)fileMap.get("error_yn"))){

			mav.addObject("msg",fileMap.get("error_msg"));
			return mav;
		}
		
		//파일삭제
		if(vo.getDel_p_logo() !=null && !"".equals(vo.getDel_p_logo())){
			File delfile = new File(req.getSession().getServletContext().getRealPath(vo.getDel_p_logo()));
			if(delfile.isFile()){
				delfile.delete();
			}
		}
		if(vo.getDel_footer_logo() != null && !"".equals(vo.getDel_footer_logo() )){
			File delfile = new File(req.getSession().getServletContext().getRealPath(vo.getDel_footer_logo()));
			if(delfile.isFile()){
				delfile.delete();
			}
		}
		if(vo.getDel_event_img() != null && !"".equals(vo.getDel_event_img() )){
			File delfile = new File(req.getSession().getServletContext().getRealPath(vo.getDel_event_img()));
			if(delfile.isFile()){
				delfile.delete();
			}
		}
		
		if(vo.getDel_c_back_img() != null && !"".equals(vo.getDel_c_back_img() )){
			File delfile = new File(req.getSession().getServletContext().getRealPath(vo.getDel_c_back_img()));
			if(delfile.isFile()){
				delfile.delete();
			}
		}
		//파일삭제 끝
		
		
		if(null!=fileMap.get("p_logo")){
			vo.setP_logo((String) fileMap.get("p_logo"));
		}
		if(null!=fileMap.get("footer_logo")){
			vo.setFooter_logo((String) fileMap.get("footer_logo"));
		}
		if(null!=fileMap.get("event_img")){
			vo.setEvent_img((String) fileMap.get("event_img"));
		}
		if(null!=fileMap.get("c_back_img")){
			vo.setC_back_img((String) fileMap.get("c_back_img"));
		}
		
		service.peti400T(vo);
		mav.addObject("msg","수정되었습니다.");
		
		return mav;
		
	}
	
	/**
	 * 객실관리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti500Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//객실정보
		mav.addObject("list", service.peti500Q(vo));
		
		return mav;
	}
	
	/**
	 * 객실등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti501Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//펜션 그룹정보
		mav.addObject("groupList", service.peti501Q(vo));
		
		return mav;
	}
	
	/**
	 * 객실 등록 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti501T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","등록되었습니다.");
		service.peti501T(vo);

		
		return mav;
	}
	
	/**
	 * 펜션 상세조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti502Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		mav.addObject("r_map", service.peti502Q(vo));
		//펜션 그룹정보
		mav.addObject("groupList", service.peti501Q(vo));
		
		return mav;
	}
	
	/**
	 * 펜션 수정 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti502T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다.");
		service.peti502T(vo);

		
		return mav;
	}
	
	/**
	 * 순서 변경
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti503T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다.");
		service.peti503T(vo);

		
		return mav;
	}
	
	/**
	 * sms 충전 목록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti600Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		mav.addObject("list", service.peti600Q(vo));
		
		return mav;
	}
	
	/**
	 * sms 충전 등록 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti600T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti600Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","등록되었습니다.");
		service.peti600T(vo);
		
		return mav;
	}
	
	/**
	 * sms 충전 삭제 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti601T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti600Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","삭제되었습니다.");
		service.peti601T(vo);
		
		return mav;
	}
	
	/**
	 * sms 기본 요금 변경
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti602T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti600Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","기본요금이 변경되었습니다.");
		service.peti602T(vo);
		
		return mav;
	}
	
	/**
	 * 부가서비스 목록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti700Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("map", service.peti301Q(vo));
		mav.addObject("list", service.peti700Q(vo));
		
		return mav;
	}
	
	/**
	 * 부가서비스 등록 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti700T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","등록되었습니다.");
		service.peti700T(vo);
		
		return mav;
	}
	
	/**
	 * 부가서비스 수정 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti701T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다.");
		service.peti701T(vo);
		
		return mav;
	}
	
	/**
	 * 부가서비스 삭제 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti702T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti700Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","삭제되었습니다.");
		service.peti702T(vo);
		
		return mav;
	}
	
	/**
	 * 핫이슈 공지 게시판 목록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti800Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
//		mav.addObject("map", service.peti800Q(vo));
		PaginationInfo paginationInfo = new PaginationInfo();
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));


		int iTotalCnt = service.peti800_1Q(vo);
		vo.setTotalRecordCount(iTotalCnt);
		
		if(iTotalCnt>0){
			
			// 상위 코드목록
			mav.addObject("list", service.peti800_2Q(vo));
			mav.addObject("pageHtml", vo.getToHtml("./peti800Q.do"));
			mav.addObject("paginationInfo", vo);
		}
		mav.addObject("map", service.peti301Q(vo));
		return mav;
	}
	
	/**
	 * 게시판 핫이슈 등록 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti800T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti800Q.do?p_id="+vo.getP_id()+"&sb_type="+vo.getSb_type());
		mav.addObject("msg","저장되었습니다.");
			
		service.peti800T(vo);
		return mav;
	}
	
	/**
	 * 게시판 핫이슈 수정 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti801T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti800Q.do?p_id="+vo.getP_id()+"&sb_type="+vo.getSb_type());
		mav.addObject("msg","수정되었습니다.");
		service.peti801T(vo);
		return mav;
	}
	
	/**
	 * 게시판 핫이슈 삭제 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti802T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti800Q.do?p_id="+vo.getP_id()+"&sb_type="+vo.getSb_type());
		mav.addObject("msg","삭제되었습니다.");
		service.peti802T(vo);
		return mav;
	}
	
	/**
	 * 예약관리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti900Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();

		if(null != vo.getSrc_sdate() && !"".equals(vo.getSrc_sdate())){
			vo.setSrc_sdate(vo.getSrc_sdate().replaceAll("-", "")+"000000");
		}
		
		if(null != vo.getSrc_edate() && !"".equals(vo.getSrc_edate())){
			vo.setSrc_edate(vo.getSrc_edate().replaceAll("-", "")+"999999");
		}
		
		if(null != vo.getSrc_val()  && !"".equals(vo.getSrc_val())){
			vo.setSrc_val("%"+vo.getSrc_val()+"%");
		}
		
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));


		int iTotalCnt = service.peti900_1Q(vo);
		vo.setTotalRecordCount(iTotalCnt);
		
		if(iTotalCnt>0){
			List list = service.peti900_2Q(vo);
			List returnList = new ArrayList();
			for(int i=0; i< list.size();i++){
				Map data = (Map) list.get(i);
				String info1 = (String)data.get("reservation_info");
				String info2 = (String)data.get("cancel_info");
				
				if(null != info1 && !"".equals(info1)){
//					(이용요금;입실일;등록일;입금완료일,상태)
					String[] arInfo1 = info1.split(":");;
					data.put("rc_pay", arInfo1[0]);
					data.put("reservation_dt", arInfo1[1]);
					data.put("rc_reg_dt", arInfo1[2]);
					data.put("sc_dt", arInfo1[3]);
					data.put("rc_c_reg_dt", arInfo1[3]);
					data.put("rc_status", arInfo1[4]);
					if(null != info2 && !"".equals(info2)){
						//환불도 있을경우
						String[] arInfo2 = info2.split(":");

						data.put("c_rc_pay", arInfo2[0]);
						data.put("c_reservation_dt", arInfo2[1]);
						data.put("c_cc_sc_dt", arInfo2[2]);
						data.put("c_cc_status", arInfo2[3]);
						data.put("c_cc_re_pay", arInfo2[4]);
						if(arInfo2.length>5){
							data.put("c_cc_re_status", arInfo2[5]);	
							data.put("c_cc_re_no", arInfo2[6]);	
						}
					}
				}else{
//					이용요금;입실일;취소일;상태;환불금;환불상태;환불고유번호
					if(null != info2 && !"".equals(info2)){
						String[] arInfo2 = info2.split(":");

						data.put("rc_pay", arInfo2[0]);
						data.put("reservation_dt", arInfo2[1]);
						data.put("cc_sc_dt", arInfo2[2]);
						data.put("cc_status", arInfo2[3]);
						data.put("cc_re_pay", arInfo2[4]);
						if(arInfo2.length>5){
							data.put("cc_re_status", arInfo2[5]);	
							data.put("cc_re_no", arInfo2[6]);	
						}
						
					}
				}

				
				returnList.add(data);
			}
			// 상위 코드목록
			mav.addObject("list", returnList);
			mav.addObject("pageHtml", vo.getToHtml("./peti900Q.do"));
			mav.addObject("paginationInfo", vo);
		}

		return mav;
	}
	
	/**
	 * 관리자 관리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1000Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();

		PaginationInfo paginationInfo = new PaginationInfo();
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));

		mav.addObject("list", service.peti1000Q(vo));
//
//		int iTotalCnt = service.peti1000Q(vo);
//		vo.setTotalRecordCount(iTotalCnt);
//		
//		if(iTotalCnt>0){
//			
//			// 상위 코드목록
//			
//			mav.addObject("pageHtml", vo.getToHtml("./peti900Q.do"));
//			mav.addObject("paginationInfo", vo);
//		}

		return mav;
	}
	
	/**
	 * 관리자 등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1001Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		
		return mav;
	}
	
	
	/**
	 * 관리자 등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1001T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti1001Q.do");
		mav.addObject("msg","등록되었습니다.");
		service.peti1001T(vo);
		return mav;
	}
	
	/**
	 * 관리자 수정
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1002T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti1001Q.do");
		mav.addObject("msg","수정되었습니다.");
		service.peti1002T(vo);
		return mav;
	}
	
	/**
	 * 관리자 삭제
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1003T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti1001Q.do");
		mav.addObject("msg","삭제되었습니다.");
		service.peti1003T(vo);
		return mav;
	}
	
	/**
	 * 로그인페이지
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1100Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();
		
		return mav;
	}
	
	/**
	 * 관리자 로그인 처리
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1101Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();
		Map adminUsr = service.peti1101_1Q(vo);
		Captcha captcha = (Captcha) req.getSession().getAttribute(Captcha.NAME);
		
		if(captcha!=null){
			if(vo==null ||  vo.getAnswer()==null ||!captcha.isCorrect(vo.getAnswer())){
				mav.setViewName("pmgr/pe/ti/peti1100Q");
				mav.addObject("captcaYN","Y");
				mav.addObject("msg","아이디 또는 비밀번호 또는 입력문자가 틀립니다.");
				return mav;
			}
		}
		if(adminUsr!=null){
			int login_fail_cnt = (Integer)adminUsr.get("login_fail_cnt");
			
			if(login_fail_cnt<5 || (captcha!=null && captcha.isCorrect(vo.getAnswer()))){
			
				vo.setLogin_fail_cnt(0);
				//로그인 시간 변경
				service.peti1101_2T(vo);
				
				//로그인 실패 카운트 초기화
				adminUsr.put("login_fail_cnt", 0);
				adminUsr.put("adminYN", "Y");
				req.getSession().invalidate();
				//로그인 성공시
				req.getSession().setAttribute("userInfo", adminUsr);
				mav.setViewName("/common/close");
				mav.addObject("redirect","/chkAdm/data/info/admList.do");
				
			}else{
				//5번 이상 틀리면 캡차를 띄워준다
				mav.setViewName("pmgr/pe/ti/peti1100Q");
				mav.addObject("captcaYN","Y");
			}
		}else{
			int errorCnt = 0;
			if(req.getSession().getAttribute("fail_cnt")!=null){
				errorCnt = (Integer)req.getSession().getAttribute("fail_cnt");
			}
			errorCnt++;
			req.getSession().setAttribute("fail_cnt", errorCnt);
			
			if(errorCnt>=5){
				mav.addObject("captcaYN","Y");
			}
			
			service.peti1101_3T(vo);
			mav.setViewName("pmgr/pe/ti/peti1100Q");
		}
		return mav;
	}
	
	/**
	 * 로그아웃
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1102Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti1100Q.do");
		mav.addObject("msg","로그아웃 되었습니다");

		req.getSession().invalidate();
		
		return mav;
	}

	/**
	 * 비번변경 팝업
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1103Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		
		ModelAndView mav = new ModelAndView();
		
		return mav;
	}
	
	/**
	 * 비밀번호 변경
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1103T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		
		Map admin = (Map) req.getSession().getAttribute("userInfo");
		
		vo.setAdmin_id((String) admin.get("admin_id"));
		
		ModelAndView mav = new ModelAndView("common/toJson");
		
		Map jsonMap = new HashMap();

		jsonMap.put("cnt",service.peti1103T(vo));
		mav.addObject("map", jsonMap);
		
		return mav;
	}
	
	/**
	 * sms 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView peti1200Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();//오늘
		
		mav.addObject("startYYYY", 2012);
		
		d1.add(Calendar.YEAR,1);
		mav.addObject("endYYYY", frmDate.format(d1.getTime()).substring(0,4));

		if(null != vo.getSrc_sdate() && !"".equals(vo.getSrc_sdate())){
			vo.setSrc_sdate(vo.getSrc_sdate()+vo.getSrc_edate()+"%");
		}
		
		if(null != vo.getSrc_val()  && !"".equals(vo.getSrc_val())){
			vo.setSrc_val("%"+vo.getSrc_val()+"%");
		}
		
//		// 페이징 시작
		PaginationInfo paginationInfo = new PaginationInfo();
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));


		int iTotalCnt = service.peti1200_1Q(vo);
		vo.setTotalRecordCount(iTotalCnt);
		
		if(iTotalCnt>0){
			
			// 상위 코드목록
			mav.addObject("list", service.peti1200_2Q(vo));
			mav.addObject("pageHtml", vo.getToHtml("./peti1200Q.do"));
			mav.addObject("paginationInfo", vo);
		}
		
		return mav;
	}
	
	/**
	 * 객실예약했던 사람들 목록 출력
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView mail1300Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("list", service.peti1300Q(vo));
		
		return mav;
	}

	
	/**
	 * 메일등록폼
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView mail0101C(AddUsrVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();

		return mav;
	}
	
	/**
	 * 등록하기 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView mail0102T(AddUsrVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("redirect:./mail0101C.do");

		mailService.mail0102T(vo);
		
		return mav;
	}
	
	/**
	 * 목록 조회
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView mail0201C(AddUsrVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();
		
		mav.addObject("list", mailService.mail0201C(vo));
		return mav;
	}	
		
	/**
	 * 우편번호
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView mail0301C(AddUsrVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();

		String dong = req.getParameter("dong");
		if(dong!=null && dong.length()>1){
			dong = "%"+dong +"%";
			
			mav.addObject("list",mailService.mail0301C(dong));	
		}
		
		return mav;
	}
	
	
	
	
	
	
	
	
	
//	캠핑========================
	/**
	 * 그룹 목록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0101Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//펜션 그룹정보
		mav.addObject("groupList", service.peti501Q(vo));

		return mav;
	}
	
	/**
	 * 그룹 등록폼
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0102Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//펜션 그룹정보
		mav.addObject("groupList", service.peti501Q(vo));

		return mav;
	}
	
	/**
	 * 그룹등록 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0103T(HttpServletRequest req, HttpServletResponse res, MultipartHttpServletRequest mRqst) throws Exception {
		isAdminMember(req,res);
		PETIVo vo = new PETIVo();
		
		ModelAndView mav = new ModelAndView("/common/close");
		
		
		SMCommonUtil util = new SMCommonUtil();
		util.mapToBean(req.getParameterMap(), vo);

		MultiValueMap mulitFileMap =  mRqst.getMultiFileMap();
		
		String[] files = {"back_img"};
		Map fileMap = util.getFileInfo(mulitFileMap, mRqst.getSession().getServletContext().getRealPath(""),FILE_PATH,false, files);
		
		if("Y".equals((String)fileMap.get("error_yn"))){
			mav.addObject("msg",fileMap.get("error_msg"));
			return mav;
		}
		
		if(null!=fileMap.get("back_img")){
			vo.setBack_img((String) fileMap.get("back_img"));
		}
				
		service.petc0103T(vo);
		mav.addObject("msg","저장되었습니다.");
		
		mav.addObject("redirect","./petc0101Q.do?p_id="+ vo.getP_id());
		return mav;
	}
	
	/**
	 * 그룹 수정폼
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0104Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//펜션 그룹정보
		mav.addObject("group", service.petc0104Q(vo));
		mav.setViewName("pmgr/pe/ti/petc0102Q");
		return mav;
	}
	
	/**
	 * 그룹 수정프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0105T(HttpServletRequest req, HttpServletResponse res, MultipartHttpServletRequest mRqst) throws Exception {
		isAdminMember(req,res);
		PETIVo vo = new PETIVo();
		
		ModelAndView mav = new ModelAndView("/common/close");
		
		
		SMCommonUtil util = new SMCommonUtil();
		util.mapToBean(req.getParameterMap(), vo);

		MultiValueMap mulitFileMap =  mRqst.getMultiFileMap();
		
		String[] files = {"back_img"};
		Map fileMap = util.getFileInfo(mulitFileMap, mRqst.getSession().getServletContext().getRealPath(""),FILE_PATH,false, files);
		
		if("Y".equals((String)fileMap.get("error_yn"))){
			mav.addObject("msg",fileMap.get("error_msg"));
			return mav;
		}
		
		if(null!=fileMap.get("back_img")){
			vo.setBack_img((String) fileMap.get("back_img"));
		}
				
		service.petc0105T(vo);
		mav.addObject("msg","저장되었습니다.");
		
		mav.addObject("redirect","./petc0101Q.do?p_id="+ vo.getP_id());
		return mav;
	}
	
	/**
	 * 삭제 프로세스
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0106T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//펜션 그룹정보
		mav.addObject("groupList", service.peti501Q(vo));

		return mav;
	}
	
	/**
	 * 객실좌표 등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0107POP(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//펜션 그룹정보
		mav.addObject("group", service.petc0104Q(vo));
		//그룹에 속한 객실정보
		mav.addObject("rooms", service.petc0107POP(vo));

		return mav;
	}
	
	/**
	 * 객실 좌표 등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0108T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);

		service.petc0108T(vo);
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./petc0107POP.do?p_id="+vo.getP_id()+"&pg_no="+vo.getPg_no());
		mav.addObject("msg","수정되었습니다");

		
		return mav;
	}
	
	/**
	 * 객실 복사
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0109T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);

		int cnt = vo.getCnt();
		for(int i = 0; i < cnt;i++){
			service.petc0109T(vo);	
		}
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","복사되었습니다");
		
		return mav;
	}
	
	/**
	 * 객실명 변경
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0110T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);

		int[] pr_nos = vo.getPr_nos();
		String[] room_nms = vo.getRoom_nms();
		String p_id = vo.getP_id();
		for(int i = 0; i < pr_nos.length;i++){
			PETIVo data = new PETIVo();
			data.setP_id(p_id);
			data.setPr_no(pr_nos[i]);
			data.setRoom_nm(room_nms[i]);
//			data.setRoom_ord(i+1);
			service.petc0110T(data);	
		}
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다");
		
		return mav;
	}
	
	/**
	 * 그룹좌표등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0111POP(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		
//		System.out.println("d");
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti300Q(vo));
//		List ddd = service.peti501Q(vo);
//		System.out.println(ddd);
		//펜션 그룹정보
		mav.addObject("group", service.peti501Q(vo));
		
		return mav;
	}
	
	/**
	 * 그룹좌표 등록
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0112T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);

		service.petc0112T(vo);
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./petc0111POP.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다");
		
		return mav;
	}
	
	/**
	 * 사이트 삭제
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0113T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);

		List list = new ArrayList();
		for(int i =0; i < vo.getPr_nos().length;i++){
			list.add(vo.getPr_nos()[i]);
		}
		
		vo.setList(list);
		service.petc0113T(vo);
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./peti500Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","삭제되었습니다");
		
		return mav;
	}
	
	/**
	 * 객실 쉽게 순서설정
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0114Q(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);
		ModelAndView mav = new ModelAndView();
		//펜션정보
		mav.addObject("map", service.peti301Q(vo));
		//객실정보
		mav.addObject("list", service.peti500Q(vo));
		
		return mav;
	}
	
	
	/**
	 * 객실 순서 저장
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0115T(PETIVo vo,HttpServletRequest req, HttpServletResponse res) throws Exception {
		isAdminMember(req,res);

		int[] pr_nos = vo.getPr_nos();
		String[] room_nms = vo.getRoom_nms();
		String p_id = vo.getP_id();
		for(int i = 0; i < pr_nos.length;i++){
			PETIVo data = new PETIVo();
			data.setPr_no(pr_nos[i]);

			data.setRoom_ord(i+1);
			service.petc0115T(data);
//			UPDATE pension_rooms SET room_nm = #room_nm#, room_ord=#room_ord# WHERE pr_no = #pr_no#
		}
		
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect","./petc0114Q.do?p_id="+vo.getP_id());
		mav.addObject("msg","수정되었습니다");
		
		return mav;
	}
}
